import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:note/common/common.dart';
import '../../widgets/BasePage.dart';
import '../../widgets/divider.dart';
import 'logic.dart';

class SettingPage extends StatelessWidget {
  SettingPage({Key? key}) : super(key: key);

  final logic = Get.put(SettingPageLogic());
  final state = Get.find<SettingPageLogic>().state;

  @override
  Widget build(BuildContext context) {
    return BasePage(
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Styles.backgroundColor,
          foregroundColor: Styles.mainThemeColor,
          title: const Text(Strings.setting),
        ),
        body: ListView(
          padding: const EdgeInsets.only(top: 10),
          children: [
            setApp(),
            divider(),
            setLockTile(),
            divider(),
            cleanTile(),
            divider(),
            checkNewVersionTile(),
          ],
        ),
      ),
    );
  }

  Widget setApp() {
    return listTile(Strings.setApp, logic.onSetApp);
  }

  Widget cleanTile() {
    return listTile(Strings.cleanAllNotes, logic.onCleanAllNotes);
  }

  Widget checkNewVersionTile() {
    return listTile(Strings.checkNewVersion, logic.onCheckNewVersion);
  }

  Widget setLockTile() {
    return listTile('设置设备锁', logic.onSetLock);
  }

  Widget listTile(String text, Function()? function) {
    return ListTile(
      title: Text(
        text,
        style: Styles.textStyleNormal(20),
      ),
      onTap: function,
    );
  }

  Widget divider() {
    return Padding(
      padding: const EdgeInsets.only(left: 10, right: 10),
      child: defaultDivider(),
    );
  }
}
